package com.lcw.lostandfound.controller.backstage;

import com.lcw.lostandfound.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AUserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/backstage/user")
    public String user(Model model, @RequestParam(name = "pageNum",required = false,defaultValue = "1")Integer pageNum, @RequestParam(name = "pageSize",required = false,defaultValue = "10")Integer pageSize){
        model.addAttribute("users",userService.findUser(pageNum,pageSize));
        return "admin/user";
    }
    @ResponseBody
    @RequestMapping("/deleteUser")
    public String deleteAdmin(Integer id){
        if (userService.deleteById(id)>0) {
            return "true";
        }
        return "false";
    }
    @RequestMapping("/backstage/findUserByName")
    public String findUserByName(Model model,String username){
        model.addAttribute("user",userService.findByName(username));
        return "admin/findUser";
    }
}
